package cn.com.baiwei.controller;

import cn.com.baiwei.dto.SupplyDto;
import cn.com.baiwei.pojo.PurchaseOrder;
import cn.com.baiwei.pojo.ReceiptOrder;
import cn.com.baiwei.pojo.Supplier;
import cn.com.baiwei.service.impl.WholeOrderServiceImpl;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author youngMoney
 * @Description //TODO $
 * @Date $ $
 * @Param $
 * @return $
 **/
@RestController
@RequestMapping("/wholeOrder")
@Api(value = "完整进货单(PurchaseOrder和List<OrderDetails>)管理",tags = "完整进货单(wholeOrder)管理接口API")
@ApiResponses({
        @ApiResponse(code=400,message="请求参数不完整或者错误"),
        @ApiResponse(code=404,message="找不到页面"),
        @ApiResponse(code=405,message="请求方式不正确，比如后台接收是post，但前端请求的是get"),
        @ApiResponse(code=406,message="页面地址和接口名冲突"),
        @ApiResponse(code=415,message="请求格式不正确，前端可能没有把请求头修改为json，也可能前端请求的json对象没有转换为字符串"),
        @ApiResponse(code=500,message="后台服务逻辑错误")
})
public class WholeOrderController {
    @Resource
    private WholeOrderServiceImpl wholeOrderService;

    /**
     * 通过一个dto对象新增单条数据
     *
     * @param supplyDto 一个数据库对应的dto数据对象
     * @return 返回插入的主键id
     */
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    @ApiOperation(value = "根据完整记录新增一个包括详情的完整订单的接口",notes = "根据完整记录新增一个包括详情的完整订单的接口",httpMethod = "POST")
    public Map<String, Object> insert(@RequestBody @ApiParam(name = "supplyDto",value = "pojo模型",required = true) SupplyDto supplyDto) {
        return this.wholeOrderService.insert(supplyDto);
    }


    /**
     * 通过多个供货商订单的id 组成的List 提交多个订单 并更新状态
     *
     * @param purchaseOrderIdList 一个数据库对应的pojo供货商订单数据对象
     * @return 返回插入的主键id
     */
    @RequestMapping(value = "/submitOrder", method = RequestMethod.POST)
    @ApiOperation(value = "提交供货商订单的接口",notes = "提交供货商订单的接口",httpMethod = "POST")
    public Map<String, Object> submitOrder(@RequestBody @ApiParam(name = "purchaseOrderIdList",value = "List",required = true) List<Integer> purchaseOrderIdList) {
        return this.wholeOrderService.submitOrder(purchaseOrderIdList);
    }

    /**
     * 通过订单编号验收入库 更改订单状态并更新库存
     *
     * @param receiptOrder 一个数据库对应的pojo收货单数据对象
     * @return 返回插入的主键id
     */
    @RequestMapping(value = "/receipt", method = RequestMethod.POST)
    @ApiOperation(value = "根据订单收货入库的接口",notes = "根据订单收货入库的接口",httpMethod = "POST")
    public Map<String, Object> receipt(@RequestBody @ApiParam(name = "purchaseOrderIdList",value = "List",required = true) ReceiptOrder receiptOrder) {

        return this.wholeOrderService.receipt(receiptOrder);
    }

    /**
     * 通过订单编号快速查询 进货单数据以及进货单详情
     *
     * @param orderId 订单编号
     * @return 返回插入的主键id
     */
    @RequestMapping(value = "/selectWhole", method = RequestMethod.GET)
    @ApiOperation(value = "根据订单编号查询进货单及详情的接口",notes = "根据订单收货入库的接口",httpMethod = "GET")
    public Map<String, Object> receipt(@RequestParam @ApiParam(name = "orderId",value = "String",required = true)String  orderId) {

        return this.wholeOrderService.selectWhole(orderId);
    }





}
